<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>功能列表</title>
    <div th:include="layout/resources :: resources"></div>
</head>
<body>
<div>
    <div class="container-fluid">
        <div id="toolbar" class="btn-group">
            <button onclick="toAdd();">添加</button>
        </div>
        <table id="list"></table>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
    })
    $("#list").framework().bootstrapTable({
        url: "/fun/getListByPage",
        columns: [{
            field: '',
            title: '序号',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'id',
            title: '操作',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return '<a href="javascript:deleteOne(\'' + value + '\',false);">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:deleteOne(\'' + value + '\',true);">删除账号</a>';
            }
        }, {
            field: 'fun',
            title: 'Fun',
            align: 'center',
            valign: 'middle'
        }, {
            field: 'describe',
            title: '项目名',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return '<a href="javascript:toFlowList(' + row.fun + ');">' + value + '</a>';
            }
        }, {
            field: 'remark',
            title: '备注',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {

                if (value) {
                    return '<a href="javascript:updateRemark(' + row.fun + ');">' + value + '</a>';
                } else {
                    return '<a href="javascript:updateRemark(' + row.fun + ');">添加备注</a>';
                }

            }
        }]
    });

    function refresh() {
        $('#list').bootstrapTable('refresh');
    }
    function deleteOne(id, flag) {

        layer.confirm(flag == true ? '确认删除账号信息吗？' : '删除功能同时会清除账号信息，确认删除吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                method: "get",
                url: createUrl('/fun/delete?id=' + id + "&onlyDeleteAccount=" + flag),
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("删除成功");
                    } else {
                        framework.alert("删除失敗:" + result.error);
                    }
                    layer.close(index);
                }
            })
        }, function () {
            layer.closeAll();
        });
    }
    function toAdd() {
        framework.openWindow("/fun/toAdd", "50%", "50%", "添加项目类型");
    }

    function toFlowList(fun) {
        parent.framework.openWindow("/fun/toFlowList/" + fun, "90%", "90%", "流程列表");
    }

    function updateRemark(fun) {
        layer.prompt({title: '修改备注', formType: 2}, function (text, index) {
            $.ajax({
                method: "post",
                url: createUrl("/fun/updateReamrk"),
                data: {
                    fun: fun,
                    remark: text
                },
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("修改成功");
                    } else {
                        framework.alert("修改失败:" + result.error);
                    }
                    layer.closeAll();
                }
            })
        });
    }
</script>
</html>
